// @ts-nocheck
import Util from './js/util.js'
import SystemDemo from './js/systemdemo.js'

//这个函数在整个wps加载项中是第一个执行的
function OnAddinLoad(ribbonUI) {
  if (typeof wps.ribbonUI != 'object') {
    wps.ribbonUI = ribbonUI
  }

  if (typeof wps.Enum != 'object') {
    // 如果没有内置枚举值
    wps.Enum = Util.WPS_Enum
  }

  //这几个导出函数是给外部业务系统调用的
  window.openOfficeFileFromSystemDemo = SystemDemo.openOfficeFileFromSystemDemo
  window.InvokeFromSystemDemo = SystemDemo.InvokeFromSystemDemo

  wps.PluginStorage.setItem('EnableFlag', false) //往PluginStorage中设置一个标记，用于控制两个按钮的置灰
  wps.PluginStorage.setItem('ApiEventFlag', false) //往PluginStorage中设置一个标记，用于控制ApiEvent的按钮label
  return true
}

// eslint-disable-next-line no-unused-vars
var WebNotifycount = 0
function OnAction(control) {
  const eleId = control.Id
  switch (eleId) {
    case '相似度高级工具':
      {
        // alert(Util.GetUrlPath()+ '/superSimilarPane')
        let tsId = wps.PluginStorage.getItem('相似度高级工具')
        if (!tsId) {
          let tskpane = wps.CreateTaskPane(
            Util.GetUrlPath() + '/superSimilarPane',
          )
          let id = tskpane.ID
          wps.PluginStorage.setItem('相似度高级工具', id)
          tskpane.Visible = true
        } else {
          let tskpane = wps.GetTaskPane(tsId)
          tskpane.Visible = !tskpane.Visible
        }
      }
      break
    default:
      break
  }
  return true
}

function GetImage(control) {
  const eleId = control.Id
  switch (eleId) {
    case 'btnShowMsg':
      return 'images/1.svg'
    case 'btnShowDialog':
      return 'images/2.svg'
    case 'btnShowTaskPane':
      return 'images/3.svg'
    default:
  }
  return 'images/newFromTemp.svg'
}

function OnGetEnabled(control) {
  const eleId = control.Id
  switch (eleId) {
    case 'btnShowMsg':
      return true
    case 'btnShowDialog': {
      let bFlag = wps.PluginStorage.getItem('EnableFlag')
      return bFlag
    }
    case 'btnShowTaskPane': {
      let bFlag = wps.PluginStorage.getItem('EnableFlag')
      return bFlag
    }
    default:
      break
  }
  return true
}

function OnGetVisible(control) {
  const eleId = control.Id
  console.log(eleId)
  return true
}

function OnGetLabel(control) {
  const eleId = control.Id
  switch (eleId) {
    case 'btnIsEnbable': {
      let bFlag = wps.PluginStorage.getItem('EnableFlag')
      return bFlag ? '按钮Disable' : '按钮Enable'
    }
    case 'btnApiEvent': {
      let bFlag = wps.PluginStorage.getItem('ApiEventFlag')
      return bFlag ? '清除新建文件事件' : '注册新建文件事件'
    }
  }
  return ''
}

function OnNewDocumentApiEvent(doc) {
  alert('新建文件事件响应，取文件名: ' + doc.Name)
}

//这些函数是给wps客户端调用的
export default {
  OnAddinLoad,
  OnAction,
  GetImage,
  OnGetEnabled,
  OnGetVisible,
  OnGetLabel,
  OnNewDocumentApiEvent,
}
